<template>
  <div class="objectiveQuestion-warp" style="position: relative;">
    <div style="display:flex;flex-wrap: wrap;">
      <QuestionCard v-for="(item, key) in sectionQuestionList" :key="item.id" :question="item" :bordered="true" style="width:350px;margin-right:10px;margin-bottom:10px;flex-shrink:0;">
        <a slot="action">
          <span
              @click="addObjectiveQuestion(item.questionDto, 'modify')"
              v-if="item.questionDto && item.questionDto.description"
          >
            <Icon type="ios-loop-strong"></Icon>
            修改
          </span>
          <span v-else style="color:#ccc;cursor:not-allowed">修改</span>
          <Poptip
              confirm
              title="确认删除?"
              transfer
              @on-ok="delSectionQuestion(item.id)"
              v-if="!expUsed || !item.questionDto.description"
          >
            <span style="color:var(--operation-del)">
              <Icon type="ios-loop-strong"></Icon>
              删除
            </span>
          </Poptip>
          <span v-else style="color:#ccc;cursor:not-allowed">
            <Icon type="ios-loop-strong"></Icon>
            删除
          </span>
        </a>
      </QuestionCard>
    </div>
    <Modal
        v-model="addObjectiveQuestionModal.show"
        :title="addObjectiveQuestionModal.title"
        :loading="addObjectiveQuestionModal.loading"
        :mask-closable="false"
        @on-ok="saveObjectQuestion('objectiveQuestionformValidate')"
        @on-cancel="resetField('objectiveQuestionformValidate')"
        width="600px"
    >
      <Form
          ref="objectiveQuestionformValidate"
          :model="objectiveQuestionformValidate"
          :rules="ruleobjectiveQuestionValidate"
          :label-width="120"
      >
        <FormItem label="名称" prop="description">
          <Input
              v-model.trim="objectiveQuestionformValidate.description"
              placeholder="题目名称长度为1-1000个字符"
              type="textarea"
              :maxlength="1000"
              :rows="4"
          ></Input>
        </FormItem>
        <FormItem label="知识点" prop="typeCode">
          <Select filterable
              v-model="objectiveQuestionformValidate.typeCode"
              placeholder="选择知识点"
              filterable
          >
            <Option
                v-for="item in typeCodeObj"
                :key="item.dictid"
                :value="item.dictid"
                :title="item.dictname"
            >{{ item.dictname }}</Option
            >
          </Select>
        </FormItem>
        <FormItem label="题目难度" prop="difficulty">
          <Select filterable v-model="objectiveQuestionformValidate.difficulty" placeholder="选择题目难度">
            <Option value="simple">简单</Option>
            <Option value="medium">中等</Option>
            <Option value="hard">较难</Option>
          </Select>
        </FormItem>
        <FormItem label="题目类型" prop="modeCode">
          <Select filterable
              v-model="objectiveQuestionformValidate.modeCode"
              placeholder="选择题目类型"
              @on-change="changeAnswerTxt"
              :disabled="questiontypeDisbaled"
          >
            <Option :value="1">单选</Option>
            <Option :value="2">多选</Option>
            <Option :value="3">判断</Option>
          </Select>
        </FormItem>
        <FormItem label="可见范围" prop="visibility" v-if="$route.query.ispublic===undefined">
          <RadioGroup v-model="objectiveQuestionformValidate.visibility">
            <Radio label="share">单位</Radio>
            <Radio label="private" :disabled="isPublic == 1 || !isOwn">个人</Radio>
          </RadioGroup>
        </FormItem>
        <span v-show="preQuestion" class="questionclass">
          <QuestionCard
            :question="objectiveQuestionformValidate"
            :bordered="true"
          ></QuestionCard>
        </span>
        <span v-show="!preQuestion">
          <FormItem
              v-for="(item, index) in objectiveQuestionformValidate.answers"
              v-if="
              (objectiveQuestionformValidate.modeCode === 1 ||
                objectiveQuestionformValidate.modeCode === 2) &&
                item.status
            "
              :key="index"
              :label="'[' + filterIndex(index + 1) + ']'"
              :prop="'answers.' + index + '.description'"
              :rules="{ validator: answerCheck, trigger: 'change' }"
              class="answerForm"
          >
            <Row>
              <Col span="18">
                <Input
                    v-model.trim="item.description"
                    type="textarea"
                    :maxlength="200"
                    :rows="2"
                    placeholder="请输入题目答案"
                    style="margin-bottom:12px"
                />
                <!-- <Input v-model.trim="item.explanation" type="text"  placeholder="请输入题目正确答案" />-->
              </Col>
              <Col span="4" offset="1">
                <span
                    v-if="
                    (objectiveQuestionformValidate.modeCode === 2 ||
                      objectiveQuestionformValidate.modeCode === 1) &&
                      objectiveQuestionformValidate.answers.length > 1
                  "
                >
                  <Button
                      @click="handleRemove(index)"
                      :disabled="
                      objectiveQuestionformValidate.answers.filter((item) => item.status).length ===
                        1 || questiontypeDisbaled
                    "
                  >删除</Button
                  >
                </span>
                <Radio
                    v-model="item.isRight"
                    v-if="objectiveQuestionformValidate.modeCode === 1"
                    @on-change="singleAnswer(index)"
                    :true-value="1"
                    :false-value="0"
                    :disabled="questiontypeDisbaled"
                >正确答案</Radio
                >
                <Checkbox
                    v-model="item.isRight"
                    v-if="objectiveQuestionformValidate.modeCode === 2"
                    :true-value="1"
                    :false-value="0"
                    :disabled="questiontypeDisbaled"
                >正确答案</Checkbox
                >
              </Col>
            </Row>
          </FormItem>
          <FormItem
              v-if="objectiveQuestionformValidate.modeCode === 3"
              label="题目答案"
              :prop="'answers[0].isRight'"
              :rules="{
              required: true,
              type: 'number',
              message: '题目答案不能为空',
              trigger: 'change'
            }"
          >
            <RadioGroup v-model="objectiveQuestionformValidate.answers[0].isRight">
              <Radio :label="1" :disabled="questiontypeDisbaled">正确</Radio>
              <Radio :label="0" :disabled="questiontypeDisbaled">错误</Radio>
            </RadioGroup>
          </FormItem>
        </span>
        <FormItem style="margin-top:0">
          <Button
              type="primary"
              :disabled="disbledAdd"
              v-if="
              objectiveQuestionformValidate.modeCode === 2 ||
                objectiveQuestionformValidate.modeCode === 1
            "
              @click="addAnswers"
          >增加</Button
          >
          <Button
              type="primary"
              v-if="objectiveQuestionformValidate.modeCode"
              @click="showQuestion"
          >{{ preTxt }}</Button
          >
        </FormItem>
        <FormItem label="题目解析" prop="explanation">
          <Input
              v-model.trim="objectiveQuestionformValidate.explanation"
              type="textarea"
              :maxlength="1000"
              :rows="4"
              placeholder="解析信息"
          />
        </FormItem>
      </Form>
    </Modal>
    <Modal
        v-model="preQuestionModal"
        :footer-hide="true"
        :width="800"
        title="题目预览"
        :mask-closable="false"
    >
      <Card>
        <p slot="title" style="word-break: break-all;overflow: visible;white-space: inherit;">
          <Tag color="#2f70ff">{{
              preQuestionDataObj.modeCode === 1
                  ? '单选'
                  : preQuestionDataObj.modeCode === 2
                      ? '多选'
                      : '判断'
            }}</Tag>
          <span v-text="preQuestionDataObj.description">{{ preQuestionDataObj.description }}</span>
        </p>
        <p
            v-if="preQuestionDataObj.modeCode === 1 || preQuestionDataObj.modeCode === 2"
            v-for="(item, index) in preQuestionDataObj.answers"
            :key="index"
            :style="item.isRight ? 'color:var(--answer-right)' : 'color:var(--default-color-level2)'"
            style="word-break: break-all;margin-bottom:10px"
        >
          <span>[{{ item.no | noFilter }}]</span>
          <span v-text="item.description">{{ item.description }}</span>
        </p>
        <template v-if="preQuestionDataObj.modeCode === 3">
<!--          {{ preQuestionDataObj.answers[0].isRight ? '正确' : '错误' }}-->
          <p
              :style="preQuestionDataObj.answers[0].isRight ? 'color:var(--answer-right)' : 'color:var(--default-color-level2)'"
              style="word-break: break-all;margin-bottom:10px"
          >
            <span>[{{ filterIndex(1) }}]</span> 正确
          </p>

          <p
              :style="!preQuestionDataObj.answers[0].isRight ? 'color:var(--answer-right)' : 'color:var(--default-color-level2)'"
              style="word-break: break-all;margin-bottom:10px">
            <span>[{{ filterIndex(2) }}]</span> 错误
          </p>
        </template>
        <p
            style="color:var(--default-color-level2);font-size: 12px;margin-top:10px;border-top:1px solid #eee;padding-top: 10px"
        >
          解析：<span
            v-if="preQuestionDataObj.explanation"
            v-text="preQuestionDataObj.explanation"
        >{{ preQuestionDataObj.explanation }}</span
        ><span v-else>暂无解析</span>
        </p>
      </Card>
    </Modal>
  </div>
</template>
<script>
import usally from '@/mixin/usally';
import { allDirection } from '@/api/dict';
import {
  queryObjectiveList,
  delQuestion,
  createQuestion,
  queryObjectiveAnswerList,
  modifyQuestion,
  getQuestionAndAnswer
} from '@/api/question';
import { delSectionQuestion, querySectionQuestion, addSectionQuestion } from '@/api/guide.js';
import encryption from '@/libs/encryption.js';
import { escape2Html } from '@/libs/utils';
import { validateNameCustom,newValidationRules} from '@/libs/reg.js'
import QuestionCard from '@/components/question-list/question-card.vue'
export default {
  name: 'sectionQuestion',
  components:{QuestionCard},
  props: ['showAddQuestion', 'sectionId', 'guideID', 'expUsed', 'isPublic', 'isOwn'],
  mixins: [usally],
  data() {
    // const typeCodelen = (rule, value, callback) => {
    // 			if(value.length > 5) {
    // 				callback(new Error('最多选择5个知识点'));
    // 			}
    // 			callback();
    // 		}
    //	        const validateName = (rule, value, callback) => { //验证只能填入数字
    //		      	var reg = new RegExp("^[\u4E00-\u9FA5a-zA-Z0-9_ -]*$");
    //		      	//验证警戒值
    //		      	if(value){
    //		      		if (!reg.test(value)) {
    //		      			callback(new Error('请输入中文、数字、字母、下划线、-'));
    //		      		}else{
    //		      			callback()
    //		      		}
    //		      	}else{
    //		      		callback()
    //		      	}
    //		    }
    const validateName = (rule, value, callback) => {
      //验证警戒值
      if (value) {
        validateNameCustom(rule, value, callback, 1000)
      } else {
        callback()
      }
    }
    let September = sessionStorage.getItem('November');
    September = JSON.parse(encryption.SelfUseDecrypt(September));
    return {
      creatByMeModal: false,
      USER_ID: September.userId,
      USER_Name: September.nickname,
      isRootDesigner: September.isRootDesigner,
      // 页面设置
      fullHeight: document.documentElement.clientHeight,
      fullWidth: document.documentElement.clientWidth,
      setHei: 'auto',
      preQuestionDataObj: {},
      preQuestionModal: false,
      preQuestion: false,
      disbledAdd: false,
      preTxt: '预览',
      questiontypeDisbaled: false,
      objective: {
        questionname: '',
        page: 1,
        pageSize: 10,
        visibility: 'all'
      },
      objectListTotal: 0,
      objectiveList: [],
      typeCodeObj: [],
      index: 1,
      addObjectiveQuestionModal: {
        show: false,
        title: '创建客观题',
        loading: true,
        opType: 'add'
      },
      questionAnswer: '题目答案(单选)',
      objectiveQuestionformValidate: {
        description: '',
        typeCode: '',
        difficulty: '',
        modeCode: '',
        explanation: '',
        visibility: 'share',
        answers: [
          {
            index: 1,
            answerID: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 0,
            questionId: '',
            status: 1
          }
        ]
      },
      ruleobjectiveQuestionValidate: {
        description: [
          {
            required: true,
            max: 1000,
            message: '题目名称长度为1-1000个字符',
            trigger: 'change'
          },
          { validator: validateName, trigger: 'change' }
        ],
        typeCode: [
          {
            required: true,
            message: '知识点不能为空',
            trigger: 'change'
          }
        ],
        difficulty: [
          {
            required: true,
            message: '难度不能为空',
            trigger: 'change'
          }
        ],
        modeCode: [
          {
            required: true,
            type: 'number',
            message: '类型不能为空',
            trigger: 'change'
          }
        ],
        visibility: [
          {
            required: true,
            message: '可见范围不能为空',
            trigger: 'change'
          }
        ]
      },
      initQuestionObj: {
        answers: [
          {
            answerID: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 0,
            questionId: ''
          }
        ],
        visibility: 'share',
        description: '',
        difficulty: '',
        enabled: 1,
        explanation: '',
        modeCode: 0,
        questionID: '',
        timer: 0,
        typeCode: ''
      },
      // 显示
      showDataList: false,
      showDefImg: false,
      //段落题目
      showTab: 'create',
      sectionQuestionList: []
    };
  },
  computed: {},
  filters: {
    noFilter(val) {
      let str;
      switch (val) {
        case 1:
          str = 'A';
          break;
        case 2:
          str = 'B';
          break;
        case 3:
          str = 'C';
          break;
        case 4:
          str = 'D';
          break;
        case 5:
          str = 'E';
          break;
        case 6:
          str = 'F';
          break;
        case 7:
          str = 'G';
          break;
        case 8:
          str = 'H';
          break;
        case 9:
          str = 'I';
          break;
        case 10:
          str = 'J';
          break;
        case 11:
          str = 'K';
          break;
        case 12:
          str = 'L';
          break;
        default:
          str = '';
          break;
      }
      return str;
    }
  },
  methods: {
    answerCheck(rule, value, callback) {
      console.log(this.objectiveQuestionformValidate.answers);
      if (value === '') {
        callback(new Error('题目答案不能为空'));
      }
      const len = this.objectiveQuestionformValidate.answers.filter(
          (item) => item.description == value
      );
      if (len.length > 1) {
        callback(new Error('不能输入相同的选项'));
      } else {
        callback();
      }
      callback();
    },
    // 设置样式
    //			setStyle() {
    //				window.fullHeight = document.documentElement.clientHeight;
    //				window.fullWidth = document.documentElement.clientWidth;
    //				this.fullHeight = window.fullHeight;
    //				this.fullWidth = window.fullWidth;
    //				let num = this.fullHeight - 200
    //				this.setHei = this.fullHeight - 60 - 75 + 'px'
    //				this.objective.pageSize = Math.floor(num / 96)
    //			},
    filterIndex(val) {
      // if (this.objectiveQuestionformValidate.modeCode === 3) {
      //   val = 0;
      // }
      let str = '';
      switch (val) {
        case 1:
          str = 'A';
          break;
        case 2:
          str = 'B';
          break;
        case 3:
          str = 'C';
          break;
        case 4:
          str = 'D';
          break;
        case 5:
          str = 'E';
          break;
        case 6:
          str = 'F';
          break;
        case 7:
          str = 'G';
          break;
        case 8:
          str = 'H';
          break;
        case 9:
          str = 'I';
          break;
        case 10:
          str = 'J';
          break;
        case 11:
          str = 'K';
          break;
        case 12:
          str = 'L';
          break;
        default:
          str = '';
          break;
      }
      return str;
    },
    initFormData() {
      let ispublic = this.$route.query.ispublic
      this.objectiveQuestionformValidate = {
        description: '',
        typeCode: '',
        difficulty: '',
        modeCode: '',
        explanation: '',
        visibility: ispublic===0?'private':'share', // 跟着指导书的课件范围走
        answers: [
          {
            index: 1,
            answerID: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 1,
            questionId: '',
            status: 1
          },
          {
            index: 2,
            answerID: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 2,
            questionId: '',
            status: 1
          },
          {
            index: 3,
            answerID: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 3,
            questionId: '',
            status: 1
          },
          {
            index: 4,
            answerID: '',
            description: '',
            enabled: 1,
            explanation: '',
            isRight: 0,
            no: 4,
            questionId: '',
            status: 1
          }
        ]
      };
    },
    getAllPoint() {
      let _this = this;
      let params = {
        dictTypeID: 'directionType'
      };
      allDirection(params).then((data) => {
        if (data.code === 1) {
          _this.typeCodeObj = data.attribute.attribute[0].dictEntryList;
        }
      });
    },
    addObjectiveQuestion(obj, type) {
      let _this = this;
      _this.preQuestion = false;
      _this.preTxt = '预览';
      _this.disbledAdd = false;
      _this.questiontypeDisbaled = false;
      _this.addObjectiveQuestionModal.show = true;
      _this.resetField('objectiveQuestionformValidate');
      if (type === 'add') {
        _this.addObjectiveQuestionModal.title = '添加段落题目';
        _this.initFormData();
        _this.index = 1;
      } else {
        _this.addObjectiveQuestionModal.title = `修改客观题`;
        _this.questiontypeDisbaled = true;
        queryObjectiveAnswerList(obj.id).then((data) => {
          if (data.code === 1) {
            _this.objectiveQuestionformValidate.answers = data.data.answers.map((item) => {
              if (item.description.indexOf('】') == 2 || item.description.indexOf(']') == 2) {
                item.description = escape2Html(item.description.slice(3));
              }
              item.status = 1;
              return item;
            });
            _this.objectiveQuestionformValidate.answers.sort(function(a, b) {
              return a.no > b.no ? 1 : -1;
            });
          }
        });
        _this.changeAnswerTxt(obj.modeCode);
        obj.difficulty = obj.difficulty.toLowerCase();
        Object.assign(_this.objectiveQuestionformValidate, obj, {
          typeCode: obj.typeCode.toString()
        }); //obj.typeCode.split(',')
      }
    },
    saveObjectQuestion(name) {
      let _this = this;
      _this.$refs[name].validate((valid) => {
        if (valid) {
          let obj = {};
          Object.assign(obj, _this.initQuestionObj, _this.objectiveQuestionformValidate);
          if (obj.answers.every((answer) => !answer.isRight) && obj.modeCode == '1') {
            this.$Message.error('请选择1个正确答案!');
            this.addObjectiveQuestionModal.loading = false;
            setTimeout(function() {
              _this.addObjectiveQuestionModal.loading = true;
            });
            return;
          } else if (
              obj.answers.filter((answer) => answer.isRight).length < 2 &&
              obj.modeCode == '2'
          ) {
            this.$Message.error('请至少选择2个正确答案!');
            this.addObjectiveQuestionModal.loading = false;
            setTimeout(function() {
              _this.addObjectiveQuestionModal.loading = true;
            });
            return;
          }
          if (obj.modeCode === 3) {
            obj.answers = obj.answers.slice(0, 1);
            obj.answers[0].description = '';
          }
          let copyObj = JSON.parse(JSON.stringify(obj));
          copyObj.answers.forEach((answer, index) => {
            answer.no = index + 1;
            answer.description = answer.description;
          });
          if (_this.addObjectiveQuestionModal.title === '添加段落题目') {
            createQuestion(copyObj).then((data) => {
              if (data.code === 1) {
                _this.$Message.info('增加题目成功！');
                //_this.queryObjectQuestionList();
                _this.addObjectiveQuestionModal.show = false;
                _this.addSectionQuestion(data.data);
                //							_this.$emit('setQuestionId',data.data.items.questionID);
              } else {
                _this.objectiveQuestionformValidate.answers.forEach(
                    (item) => (item.description = item.description.slice(3))
                ); //返回错误信息的时候保持选项内容的格式
                _this.$Message.error(data.message);
                this.addObjectiveQuestionModal.loading = false;
                setTimeout(function() {
                  _this.addObjectiveQuestionModal.loading = true;
                });
              }
            });
          } else {
            modifyQuestion(copyObj, copyObj.id).then((data) => {
              if (data.code === 1) {
                _this.$Message.info('修改题目成功！');
                //_this.queryObjectQuestionList();
                _this.addObjectiveQuestionModal.show = false;
                _this.querySectionQuestion();
              } else {
                _this.objectiveQuestionformValidate.answers.forEach(
                    (item) => (item.description = item.description.slice(3))
                ); //返回错误信息的时候保持选项内容的格式
                this.addObjectiveQuestionModal.loading = false;
                setTimeout(function() {
                  _this.addObjectiveQuestionModal.loading = true;
                });
                _this.$Message.error(data.message);
              }
            });
          }
        } else {
          this.addObjectiveQuestionModal.loading = false;
          setTimeout(function() {
            _this.addObjectiveQuestionModal.loading = true;
          });
          this.$Message.error('表单输入有误，请仔细检查是否有必填项没有输入!');
        }
      });
    },
    resetField(name) {
      if (this.$refs[name]) {
        this.$refs[name].resetFields();
      }
    },
    addAnswers() {
      this.index++;
      this.objectiveQuestionformValidate.answers.push({
        description: '',
        explanation: '',
        index: this.index,
        status: 1,
        isRight: 0,
        answerID: '',
        no: 0,
        enabled: 1,
        questionId: this.objectiveQuestionformValidate.questionID || ''
      });
    },
    handleRemove(index) {
      this.objectiveQuestionformValidate.answers[index].status = 0;
      this.objectiveQuestionformValidate.answers.splice(index, 1);
      this.index--;
      this.objectiveQuestionformValidate.answers.forEach((item, index) => {
        item.index = index + 1;
      });
    },
    changeAnswerTxt(val) {
      this.preQuestion = false;
      this.preTxt = '预览';
      this.disbledAdd = false;
      this.objectiveQuestionformValidate.answers = [
        {
          index: 1,
          answerID: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 1,
          questionId: '',
          status: 1
        },
        {
          index: 2,
          answerID: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 2,
          questionId: '',
          status: 1
        },
        {
          index: 3,
          answerID: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 3,
          questionId: '',
          status: 1
        },
        {
          index: 4,
          answerID: '',
          description: '',
          enabled: 1,
          explanation: '',
          isRight: 0,
          no: 4,
          questionId: '',
          status: 1
        }
      ];
    },
    singleAnswer(val) {
      this.objectiveQuestionformValidate.answers.forEach((item) => {
        item.isRight = 0;
      });
      this.objectiveQuestionformValidate.answers[val].isRight = 1;
    },
    showQuestion() {
      if (!this.preQuestion) {
        if (!this.objectiveQuestionformValidate.description) {
          this.$Message.info('请输入题目名称');
          return false;
        }
        if (this.objectiveQuestionformValidate.modeCode != 3) {
          if (
              this.objectiveQuestionformValidate.answers.every(
                  (item) => item.isRight == '' || item.isRight == 0
              )
          ) {
            this.$Message.info('请输入正确选项');
            return false;
          }
        }
      }
      if (this.preQuestion) {
        this.preTxt = '预览';
        this.disbledAdd = false;
      } else {
        this.preTxt = '返回';
        this.disbledAdd = true;
      }
      this.preQuestion = !this.preQuestion;
    },
    preQuestionFn(obj) {
      let params = {
        chaId: obj.questionID,
        type: obj.modeCode
      };
      getQuestionAndAnswer(params).then((data) => {
        if (data.code === 1) {
          let _this = this;
          _this.preQuestionModal = true;
          data.attribute.data.questionList[0].answers.forEach((answer) => {
            if (answer.description.indexOf('】') == 2 || answer.description.indexOf(']') == 2) {
              answer.description = escape2Html(answer.description.slice(3));
            }
          });
          _this.preQuestionDataObj = data.attribute.data.questionList[0];
          this.sortQuestionAnswer(this.preQuestionDataObj.answers);
        } else {
          _this.$Message.error(data.message);
        }
      });
    },
    // 按钮点击状态
    //			setReBtnStatus(params) {
    //				let userid = params.creator;
    //				if(userid === this.USER_ID || this.isRootDesigner) {
    //					return false
    //				} else {
    //					return true
    //				}
    //			},
    // 计算index
    handleProIndex(key) {
      return (this.objective.page - 1) * this.objective.pageSize + key + 1;
    },
    pointFilter(code, obj) {
      if (code && obj.length > 0) {
        if (code.includes(',')) {
          code = code.split(',');
          return code
          .map((codes) => {
            return obj.filter((items) => items.dictid === codes)[0].dictname;
          })
          .join(',');
        } else {
          return obj.filter((item) => item.dictid === code)[0].dictname || '暂无';
        }
      }
    },
    difficultyFilter: (val) => {
      let difficultyStr = '';
      if (val) {
        val = val.toLowerCase();
      }
      switch (val) {
        case 'simple':
          difficultyStr = '简单';
          break;
        case 'commonly':
          difficultyStr = '一般';
          break;
        case 'medium':
          difficultyStr = '中等';
          break;
        case 'hard':
          difficultyStr = '较难';
          break;
      }
      return difficultyStr;
    },
    questionMode(type) {
      //1--单选  2--多选 3---判断
      let status = '';
      switch (type) {
        case 1:
          status = '单选';
          break;
        case 2:
          status = '多选';
          break;
        case 3:
          status = '判断';
          break;
        default:
          status = '暂无';
          break;
      }
      return status;
    },
    transformPublic(val) {
      if (val === 0) {
        return 'private';
      } else if (val === 1) {
        return 'share';
      }
    },
    // 设置可见范围
    //			setVisibility(val) {
    //				let obj = {}
    //				let text = ''
    //				let color = ''
    //				if(val === 'share') {
    //					text = '单位'
    //					color = '#32CD32'
    //				} else if(val === 'private') {
    //					text = '个人'
    //					color = '#FFA1000'
    //				} else if(val === 'public') {
    //					text = '系统'
    //					color = '#4169E1'
    //				}
    //				obj.text = text
    //				obj.color = color
    //				return obj
    //			},
    // 设置知否可点击
    //			setIsClick(item) {
    //				if(item.visibility === "public" || (item.creator !== this.USER_ID && !this.isRootDesigner)) {
    //					return {
    //						'pointer-events': 'none'
    //					}
    //				}
    //			},
    //			setImgSrc(item) {
    //				if(item.visibility === "public" || (item.creator !== this.USER_ID && !this.isRootDesigner)) {
    //					return require('../../assets/project/modifys.png')
    //				} else {
    //					return require('../../assets/project/modifys-h.png')
    //				}
    //			},
    //			setDelImgSrc(item) {
    //				if(item.visibility === "public" || (item.creator !== this.USER_ID && !this.isRootDesigner)) {
    //					return require('../../assets/project/delNote-d.png')
    //				} else {
    //					return require('../../assets/project/delNote-h.png')
    //				}
    //			},
    //			changeTab(tab) {
    //				this.showTab = tab;
    //			},
    addSectionQuestion(questionId) {
      let data = [questionId];
      let sectionId = this.sectionId;
      if (!this.sectionId) {
        return;
      }
      let guideId = this.guideID;
      addSectionQuestion(guideId, sectionId, data)
      .then((data) => {
        if (data.code == 1) {
          this.querySectionQuestion();
        } else {
          this.$Message.error({
            content: data.message,
            duration: 3
          });
        }
      })
      .catch((error) => {
        console.log(error);
      });
    },
    querySectionQuestion() {
      if (!this.sectionId) {
        return;
      }
      querySectionQuestion(this.sectionId)
      .then((data) => {
        if (data.code == 1) {
          this.sectionQuestionList = data.data.items.map(item => {
            let {id,...details} = item.questionDto;
            return {
              ...item,
              ...details
            }
          });
          this.$emit('getQuestionTotal', data.data.items.length);
        } else {
          this.$Message.error({
            content: data.message,
            duration: 3
          });
        }
      })
      .catch((error) => {
        console.log(error);
      });
    },
    delSectionQuestion(id) {
      if (this.delLoading == true) {
        return;
      }
      this.delLoading = true;
      delSectionQuestion(id)
      .then((data) => {
        if (data.code == 1) {
          this.querySectionQuestion();
        } else {
          this.$Message.error(data.message);
        }
      })
      .catch((error) => {
        console.log(error);
      })
      .finally(() => {
        this.delLoading = false;
      });
    }
  },
  mounted() {
    //			this.setStyle()
    //			window.onresize = () => {
    //				this.setStyle()
    //			}
    this.querySectionQuestion();
    //    		this.queryObjectQuestionList();
    this.getAllPoint();
  },
  watch: {
    show: function(val) {
      if (val) {
        //					 this.queryObjectQuestionList();
        //    		 this.getAllPoint();
      }
    },
    sectionId(val) {
      this.querySectionQuestion();
    }
  },
  created() {}
};
</script>
<style scoped>
.page-content {
  margin-top: 20px;
  overflow-x: hidden;
  overflow-y: auto;
}


.questionclass {
  display: inline-block;
  width: calc(100% - 120px);
  margin-left: 120px;
  margin-bottom: 16px;
}

.project-item {
  width: 100%;
  border-radius: 4px;
  border: 2px solid rgb(231, 231, 241);
  padding: 10px 15px;
  margin-bottom: 15px;
}

.item-first-line {
  display: flex;
  justify-content: space-between;
}

.project-name-state {
  display: flex;
  justify-content: flex-start;
}

.project-name {
  font-size: 16px;
  font-weight: 600;
  width: 220px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
}

.project-name span {
  cursor: pointer;
  color: #2d8cf0;
}

.project-name span:hover {
  color: #57a3f3;
}

.project-status-text {
  font-weight: 600;
  font-size: 14px;
  margin-left: 10px;
  display: flex;
  justify-content: flex-start;
}

.btn-icon-wrap {
  display: flex;
  justify-content: flex-end;
}

.click-icon {
  cursor: pointer;
  height: 22px;
  margin-left: 10px;
}

.project-other-info {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 8px;
  color: rgba(51, 51, 51, 0.4);
  font-weight: bold;
}

.sendMsgContent {
  display: flex;
  justify-content: flex-start;
  margin-left: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
  width: calc(100vh - 750px);
}

.floatWrap {
  position: absolute;
  top: -50px;
  right: 15px;
  left: 260px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.question-name {
  display: inline-block;
  word-break: normal;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
